#include "database.h"

QSqlDatabase Database::db = QSqlDatabase::addDatabase("QODBC");
QSqlQuery* Database::sql = NULL;

Database::Database()
{
    qDebug()<<"数据库实例已创建";
}
bool Database::getConnection(){
    db.setHostName("127.0.0.1");
    db.setPort(3306);
    db.setDatabaseName("OnShopping");
    db.setUserName("root");
    db.setPassword("wocanima110");
    if(!db.open()){
        qDebug()<<"DataBase Error";
        qDebug()<<db.lastError().text();
        return false;
    }
    else{
        qDebug()<<"connect successed!";
        return true;
    }
}

void Database::quitConnection(){
    db.close();
}
